<template>
	<view class="ys">
		<view class="row" v-for="(item,index) in roomList" :key="index">
			<view class="title">
				<text>*</text>请填写基本信息
				<uni-icons v-if="index!=0" @click="del(index)" type="closeempty" color="#f00" size="20"
					class="icon-del"></uni-icons>
			</view>
			<view class="box">
				<view class="li">
					<text>房间名称</text>
					<view class="right">
						<input type="text" placeholder="请填写房间名称" v-model="item.roomName">
					</view>
				</view>
				<view class="li">
					<text>房间号</text>
					<view class="right">
						<input type="text" placeholder="请填写房间号" v-model="item.roomNumber">
					</view>
				</view>
				<view class="li" style="padding: 10px 0;">
					<text>房间类型</text>
					<view class="right">
						<uni-data-select :border="false" :localdata="roomRange"
							v-model="item.roomType"></uni-data-select>
					</view>
				</view>
				<view class="li">
					<text>房间面积(m²)</text>
					<view class="right">
						<input type="text" placeholder="请填写房间面积" v-model="item.roomArea">
					</view>
				</view>
				<view class="li">
					<text>房间设施</text>
					<view class="right">
						<input type="text" placeholder="请填写房间设施" v-model="item.roomFacilities">
					</view>
				</view>
				<view class="li">
					<text>租金</text>
					<view class="right">
						<input type="text" placeholder="请填写租金" v-model="item.rent">
					</view>
				</view>
				<view class="li">
					<text>押金</text>
					<view class="right">
						<input type="text" placeholder="请填写押金" v-model="item.securityDeposit">
					</view>
				</view>
				<view class="li">
					<text>租赁期限</text>
					<view class="right">
						<input type="text" placeholder="请填写租赁期限" v-model="item.leaseTerm">
					</view>
				</view>
				<view class="li">
					<text>安全设施</text>
					<view class="right">
						<input type="text" placeholder="请填写安全设施" v-model="item.safetyFacilities">
					</view>
				</view>
				<view class="li textareabox">
					<text>房间描述</text>
					<view class="right ">
						<textarea maxlength="200" placeholder="请填写房间描述" v-model="item.roomDescription" />
					</view>
				</view>
			</view>
		</view>
		<view class="footer">
			<button @click="sumbit" :loading="loading" :disabled="loading">提交</button>
		</view>
	</view>
</template>

<script>
	import {
		updateTenant,
		getTenantDetail,
	} from "@/api/api.js"
	import {
		addRoom
	} from "@/api/owner.js"
	export default {
		data() {
			return {
				id: '',
				loading: false,
				roomList: [{
					houseId: '',
					roomName: '', //房间名称
					roomNumber: '', //房间号
					roomType: '', //房间类型
					roomArea: '', //房间面积
					roomFacilities: '', //房间设施
					rent: '', //租金
					securityDeposit: '', //押金
					leaseTerm: '', //租赁期限
					safetyFacilities: '', //安全设施
					roomDescription: '', //房间描述
				}],
				roomRange: [ // 1:开间 2：一居 3：两居 4：三居 5：别墅 6：其他
					{
						text: '开间',
						value: 1
					}, {
						text: '一居',
						value: 2
					}, {
						text: '两居',
						value: 3
					}, {
						text: '三居',
						value: 4
					}, {
						text: '别墅',
						value: 5
					}, {
						text: '其他',
						value: 6
					}
				]
			}
		},
		onLoad(e) {
			if (e.id) {
				this.id = e.id
				this.roomList[0].houseId = e.id
			}
		},
		methods: {
			del(i) {
				this.roomList.splice(i, 1)
			},
			addroomList() {
				this.roomList.push({
					houseId: this.id,
					roomName: '', //房间名称
					roomNumber: '', //房间号
					roomType: '', //房间类型
					roomArea: '', //房间面积
					roomFacilities: '', //房间设施
					rent: '', //租金
					securityDeposit: '', //押金
					leaseTerm: '', //租赁期限
					safetyFacilities: '', //安全设施
					roomDescription: '', //房间描述
				})
			},
			sumbit() {

				this.loading = true
				addRoom(this.roomList).then(res => {
					uni.$showMsg(res.msg)
					this.loading = false
					if (res.code == 200) {
						setTimeout(() => {
							uni.navigateBack()
						}, 1000)
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.ys {
		background: #F1F4F3;
		height: 100%;
		min-height: 100vh;
		/* #ifdef H5 */
		min-height: calc(100vh - 44px);
		/* #endif */
		box-sizing: border-box;
		padding-top: 10px;
		padding-bottom: 70px;
	}

	radio {
		transform: scale(.7);
	}

	.imgitem {
		position: relative;
		width: 49%;

		image {
			width: 100%;
		}

		text {
			position: absolute;
			top: 75%;
			left: 50%;
			transform: translate(-50%, -50%);
			font-size: 12px;
			color: #777;
			display: block;
			text-align: center;
			width: 100%;
		}
	}


	.footer {
		position: fixed;
		bottom: 0;
		width: 100%;
		background: #fff;
		padding: 5px 10px;
		box-sizing: border-box;
		display: flex;
		align-items: center;
		justify-content: center;

		button {
			border-radius: 20px;
			width: 100%;
			margin: 0 auto;
			font-weight: bold;
			font-size: 16px;
			background: #1FFD91;
			color: #000;
		}

		.addroom {
			background: #000;
			color: #1FFD91;
		}
	}

	.row {
		padding: 0 10px;

		.title {
			display: flex;
			align-items: center;
			font-size: 14px;
			color: #777;
			margin-top: 10px;
			position: relative;

			text {
				color: #f00;
			}

			.icon-del {
				position: absolute;
				right: 0;
				top: 50%;
				transform: translate(0, -50%);
			}
		}

		.box {
			background: #fff;
			padding: 10px;
			box-sizing: border-box;
			margin-top: 10px;
			border-radius: 12px;

			textarea {
				font-size: 14px;
				width: 100%;
				box-sizing: border-box;
			}

			.li {
				display: flex;
				align-items: center;
				justify-content: space-between;
				padding: 15px 0;
				border-bottom: 1px solid #eee;

				&.textareabox {
					flex-direction: column;
					align-items: flex-start;

					.right {
						max-width: 100%;
						width: 100%;
						text-align: left;

						textarea {
							width: 100%;
							background: #f7f7f7;
							padding: 8px;
							box-sizing: border-box;
							border-radius: 6px;
							margin-top: 10px;
						}
					}
				}

				.right {
					display: flex;
					align-items: center;
					justify-content: flex-end;
					width: 62%;
					font-size: 14px;
					color: #777;
					text-align: right;


					input {
						text-align: right;
						font-size: 14px;
						width: 100%;
					}


					.time {
						background: #f2f2f2;
						width: 80px;
						display: block;
						font-size: 12px;
						height: 25px;
						line-height: 25px;
						margin: 0 4px;
						text-align: center;
						color: #777;
					}
				}

				&:last-child {
					border-bottom: 0;
				}
			}

			.noli {
				border-bottom: 0;
				padding-top: 5px;
			}
		}

		.idcard {

			.imgbox {
				display: flex;
				justify-content: space-between;
				flex-wrap: wrap;
			}

			image {
				width: 100%;
				height: 100px;
			}
		}
	}
</style>